package controller;


import biz.DeptService;
import biz.impl.DeptServiceImpl;
import dao.impl.DeptDaoImpl;
import entity.Dept;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/dept_all")
public class DeptAllController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        System.out.println("你好 Servlet");
        resp.setCharacterEncoding("UTF-8");
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
//        resp.getWriter().println("你好 老师为什么还不下课，我饿了");

        //实例化一个业务层对象
        DeptService dService=new DeptServiceImpl();

        List<Dept> depts=dService.getAll();
//        for (Dept d : depts) {
//            System.out.println(d);
//        }

        req.setAttribute("ds",depts);
        //转发
        //可以携带数据，但是地址不变
        //转发，只能转发本服务器上的路径
        req.getRequestDispatcher("index.jsp").forward(req,resp);
    }
}
